import styles from "./index.module.less";
import { map } from "lodash";

export const CODE_STATUS = {
	all: "",
	unUsed: 0,
	using: 1,
	used: 2,
	expired: -1,
	suspend: -2
};

export const formList = [
	{
		label: "全部",
		key: CODE_STATUS.all,
		value: CODE_STATUS.all
	},
	{
		label: "未使用",
		key: CODE_STATUS.unUsed,
		value: CODE_STATUS.unUsed
	},
	{
		label: "使用中",
		key: CODE_STATUS.using,
		value: CODE_STATUS.using
	},
	{
		label: "已使用",
		key: CODE_STATUS.used,
		value: CODE_STATUS.used
	},
	{
		label: "已过期",
		key: CODE_STATUS.expired,
		value: CODE_STATUS.expired
	},
	{
		label: "已停用",
		key: CODE_STATUS.suspend,
		value: CODE_STATUS.suspend
	}
];

export const getSearchOptions = (info: string) => {
	return [
		{
			type: "input",
			placeholder: "优惠码ID",
			name: "code"
		},

		{
			type: "select",
			placeholder: "使用状态",
			name: "use_status",
			options: formList
		}
	];
};

export enum SECOND_TAB_VALUES {
	//全部
	all = "",
	//满减
	fullCut = "fixed_amount",
	//折扣
	percentCut = "percentage"
}

export enum USE_RANGE_VALUE {
	//全场券
	all = "0",
	//正食
	eat = "1",
	//正气
	gas = "2"
}

export const USE_RANGE_TABS = [
	{
		label: "全场券",
		key: USE_RANGE_VALUE.all
	},
	{
		label: "正食",
		key: USE_RANGE_VALUE.eat
	},
	{
		label: "正气生活",
		key: USE_RANGE_VALUE.gas
	}
];

export const TABS = [
	{
		label: "优惠券",
		key: "discount"
	}
];

export const SECOND_OPTIONS = [
	{
		label: "全部",
		key: SECOND_TAB_VALUES.all
	},
	{
		label: "满减券",
		key: SECOND_TAB_VALUES.fullCut
	},
	{
		label: "折扣券",
		key: SECOND_TAB_VALUES.percentCut
	}
];

export const getTableColumns = ({ params, productTypeList = [] }) => [
	{
		title: "序号",
		dataIndex: "max_uses",
		width: 80,
		align: "center",
		className: styles.shop,
		valueType: "index"
		// render: (_: any, record: any, index: number) => {
		// 	const { page, limit } = params || {};
		// 	console.log(page, limit, params, _, "<=========111")
		// 	return (page - 1) * limit + index + 1; // 计算分页序号
		// }
	},
	{
		title: "名称",
		dataIndex: "name",
		width: 140,
		ellipsis: true
	},
	{
		title: "优惠码ID",
		dataIndex: "code",
		width: 140,
		ellipsis: true
	},
	{
		title: "优惠类型",
		dataIndex: "type",
		width: 140,
		renderText: (v: any) => {
			return SECOND_OPTIONS?.find(i => i?.key == v)?.label ?? "-";
		}
	},
	{
		title: "优惠方式",
		dataIndex: "discount_val",
		width: 140,
		render: (_: any, record: any) => {
			return (
				<>
					{record.type === SECOND_TAB_VALUES.fullCut ? (
						<>
							满{record.format_min_order_amount}减{record.format_discount_amount}
						</>
					) : (
						<>{Number(record.discount_val) * 100}折</>
					)}
				</>
			);
		}
	},
	{
		title: "使用范围",
		dataIndex: "category_pid",
		width: 140,
		renderText: (v: any) => {
			return productTypeList?.find(i => i?.value == v)?.label ?? "-";
		}
	},
	{
		title: "有效期",
		dataIndex: "end_time",
		width: 190,
		ellipsis: true,
		render: (_: any, record: any) => {
			return (
				<>
					<p>{`起：${record.start_time}`}</p>
					<p>{`止：${record.end_time}`}</p>
				</>
			);
		}
	},
	{
		title: "使用次数",
		dataIndex: "max_uses",
		width: 200,
		render: (_: any, record: any) => {
			return `${record.have_used}/${record.max_uses}`;
		}
	},
	{
		title: "状态",
		dataIndex: "use_status",
		width: 160,
		render: (_: any, record: any) => {
			const value = record?.use_status;
			let result: any = {};
			switch (value) {
				case CODE_STATUS.unUsed:
					result = {
						label: "未使用",
						color: "#DE6700"
					};
					break;
				case CODE_STATUS.using:
					result = {
						label: "使用中",
						color: "#3976F2"
					};
					break;
				case CODE_STATUS.used:
					result = {
						label: "已使用",
						color: "#7E7E7E"
					};
					break;
				case CODE_STATUS.expired:
					result = {
						label: "已过期",
						color: "#7E7E7E"
					};
					break;
				case CODE_STATUS.suspend:
					result = {
						label: "已停用",
						color: "#7E7E7E"
					};
					break;
				default:
					result = {
						label: "-",
						color: "#7E7E7E"
					};
					break;
			}
			return <span style={{ color: result?.color }}>{result.label}</span>;
		}
	}
];
